<script  type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.webcam.js"></script>
<script language="JavaScript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/scriptcam/swfobject.js"></script>
<script language="JavaScript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/scriptcam/scriptcam.js"></script>
<script type="text/javascript">
	$(function(){
		$("#camera").scriptcam({
			path:"<?php echo Yii::app()->request->baseUrl; ?>/js/scriptcam/",
			width:320,
			height:400,
			showMicrophoneErrors:false,
			onError:onError,
			cornerRadius:20,
			cornerColor:'e3e5e2',
			onWebcamReady:onWebcamReady,
			onPictureAsBase64:base64_tofield_and_image
		});
		
		
		$("#btnTakePicture").click(function(){
			//webcam.capture();
			savePhoto();			
		});
	});
	function base64_tofield() {
		$('#formfield').val($.scriptcam.getFrameAsBase64());
	};
	function base64_toimage() {
		$('#image').attr("src","data:image/png;base64,"+$.scriptcam.getFrameAsBase64());
	};
	function base64_tofield_and_image(b64) {
		$('#formfield').val(b64);
		$('#image').attr("src","data:image/png;base64,"+b64);
	};

	function changeCamera() {
		$.scriptcam.changeCamera($('#cameraNames').val());
	}

	function onError(errorId,errorMsg) {
		$( "#btn1" ).attr( "disabled", true );
		$( "#btn2" ).attr( "disabled", true );
		alert(errorMsg);
	}          

	function onWebcamReady(cameraNames,camera,microphoneNames,microphone,volume) {
		$.each(cameraNames, function(index, text) {
			$('#cameraNames').append( $('<option></option>').val(index).html(text) )
		});
		$('#cameraNames').val(camera);
	}
			
	function savePhoto(){
		var obj = $.scriptcam.getFrameAsBase64();
		var callback = "<?php echo $callback ?>";		
		if (callback != ""){
			//window.opener["<?php //echo $callback ?>"](obj);
			window.opener[callback](obj);
		}		
		window.close();
		
				
	}
</script>
<?php

?>
<div style="width:330px;margin-left:auto;margin-right:auto">
	<div id="camera"></div>
	<div style="margin:5px;">
		<img src="<?php echo Yii::app()->request->baseUrl; ?>/js/scriptcam/webcamlogo.png" style="vertical-align:text-top"/>
		<select id="cameraNames" size="1" onChange="changeCamera()" style="width:200px;font-size:10px;height:25px;">	
	</div>
	<div>
		<input id="btnTakePicture" type="button" value="<?php echo  Yii::t("label","Ambil gambar"); ?>" />
	</div>
</div>